package com.woniuxy.store.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.store.app.util.StoreIdUtil;
import com.woniuxy.store.client.DiningAreaClient;
import com.woniuxy.store.client.param.tableParam.AddDiningAreaParams;
import com.woniuxy.store.client.param.tableParam.LoadAllDiningAreaParams;
import com.woniuxy.store.client.param.tableParam.ModifyDiningAreaParams;
import com.woniuxy.table.client.DiningAreaMannageClient;
import com.woniuxy.table.client.DiningAreaQueryClient;
import com.woniuxy.table.client.param.AddDiningAreaParam;
import com.woniuxy.table.client.param.LoadAllDiningAreaParam;
import com.woniuxy.table.client.param.ModifyDiningAreaParam;
import com.woniuxy.table.client.result.DiningAreaClientDto;
import common.WoniuPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import javax.validation.Valid;

@RestController
@RequestMapping("/store/table")
public class DiningAreaClientImpl implements DiningAreaClient {
    @Autowired
    private DiningAreaQueryClient diningAreaQueryClient;
    @Autowired
    private DiningAreaMannageClient diningAreaMannageClient;

    @Log("查询商家区域")
    @Override
    public Result loadAllDiningArea(@Valid LoadAllDiningAreaParams loadAllDiningAreaParams) {
        LoadAllDiningAreaParam loadAllDiningAreaParam = BeanUtil.toBean(loadAllDiningAreaParams, LoadAllDiningAreaParam.class);
        loadAllDiningAreaParam.setStoreId(StoreIdUtil.getFromToken());
        Result<WoniuPage<DiningAreaClientDto>> woniuPageResult = diningAreaQueryClient.loadAllDiningArea(loadAllDiningAreaParam);
        return woniuPageResult;
    }
    @Log("添加商家区域")
    @Override
    public Result addDiningArea(@Valid AddDiningAreaParams addDiningAreaParams) {
        AddDiningAreaParam addDiningAreaParam = BeanUtil.toBean(addDiningAreaParams, AddDiningAreaParam.class);
        addDiningAreaParam.setStoreId(StoreIdUtil.getFromToken());
        Result result = diningAreaMannageClient.addDiningArea(addDiningAreaParam);
        return result;
    }
    @Log("修改商家区域")
    @Override
    public Result modifyDiningArea(@Valid ModifyDiningAreaParams modifyDiningAreaParams) {
        ModifyDiningAreaParam modifyDiningAreaParam = BeanUtil.toBean(modifyDiningAreaParams, ModifyDiningAreaParam.class);
        modifyDiningAreaParam.setStoreId(StoreIdUtil.getFromToken());
        Result result = diningAreaMannageClient.modifyDiningArea(modifyDiningAreaParam);
        return result;
    }
    @Log("删除商家区域")
    @Override
    public Result deleteDiningArea(Integer diningAreaId) {
        Result result = diningAreaMannageClient.deleteDiningArea(StoreIdUtil.getFromToken(), diningAreaId);
        return result;
    }
}
